package com.example.team.service.Imp;

import com.example.team.dao.ITestDao;
import com.example.team.entity.Test;
import com.example.team.service.ITestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 编写者：
 * 时间：
 */
//服务接口规范的方法实现
@Service
public class ITestServiceImpl implements ITestService {

    @Autowired
    private ITestDao userMapper;
    @Override
    public int insertUser(Test test) {
        int userValue;
        Test test1 =new Test();
        test1.setName(test.getName());
        List<Test> allTest =userMapper.getAllUser(test1);
        if(allTest.size()>=1){
            userValue = -1;
        }else {
            userValue= userMapper.insertUser(test);
        }
        return userValue;
    }

    @Override
    public int deleteUser(Test test) {
        int userValue;
        Test test1 =new Test();
        test1.setName(test.getName());
        List<Test> allTest =userMapper.getAllUser(test1);
        if(allTest.size()==0){
            userValue = -1;
        }else {
            userValue= userMapper.deleteUser(test);
        }
        return userValue;
    }

    @Override
    public int updateUser(Test test) {
        int userValue;
        Test test1 =new Test();
        test1.setName(test.getName());
        List<Test> allTest =userMapper.getAllUser(test1);
        if(allTest.size()>=1){
            userValue = -1;
        }else {
            userValue= userMapper.updateUser(test);
        }
        return userValue;
    }

    @Override
    public List<Test> getAllUser(Test test) {
        return userMapper.getAllUser(test);
    }

    @Override
    public Test getUser(Test test) {
        return userMapper.getUser(test);
    }
}
